<?php
	session_start();
	header("Content-type:text/html;charset=utf-8");

	$conn = 	$conn = mysqli_connect('127.0.0.1','root','pwd','admin',3306);//链接数据库('localhost','hotel','vw8jj2','consult',3308);
	mysqli_set_charset($conn,'utf8'); //设定字符集 

    if(!isset($_SESSION['user_name']))
    {
        echo "<script>alert('请您登陆后提交留言');location='consult.php';</script>";
        die;
    }
	$user_name = $_SESSION['user_name'];

	$consult = $_POST['liuyan'];
	date_default_timezone_set('PRC');
	$createtime = date("Y-m-d H:i:s");

	$insert_sql="insert into liuyan(user_name,content,createtime)values(?,?,?)";
	$stmt=mysqli_prepare($conn,$insert_sql);
	mysqli_stmt_bind_param($stmt,'sss',$user_name,$consult,$createtime);
	$result_insert=mysqli_stmt_execute($stmt);
	echo "<script>alert('留言成功');location='consult.php'</script>";
 ?>